package chapter7Sleep;

/**
 * Created by LinGer on 2019/6/18
 */
public class SleepTest extends Thread{

    private static Object obj = new Object();

    public SleepTest(String name){
        super(name);
    }

    @Override
    public void run() {
        synchronized (obj){
            try{
                for (int i = 0; i < 10; i++) {
                    System.out.println(this.getName() + ": " + i);
                    if (i % 4 == 0){
                        System.out.println(this.getName() + " sleep");
                        Thread.sleep(1000);
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        SleepTest t1 = new SleepTest("t1");
        SleepTest t2 = new SleepTest("t2");

        t1.start();
        t2.start();
    }
}
